package com.sjsm.sjsmscenerecord;

import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.MediaController;
import android.widget.RelativeLayout;
import android.widget.VideoView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by hasee on 2017/8/22.
 */

public class PlayVideoActivity extends AppCompatActivity {
    @Bind(R.id.video_view)
    VideoView mVideoView;
    private String path;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_play_video);
        ButterKnife.bind(this);
        path = getIntent().getStringExtra("path");
        initVideoView();
    }

    private void initVideoView() {
        RelativeLayout.LayoutParams layoutParams=
                new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        mVideoView.setLayoutParams(layoutParams);
        if (!path.isEmpty()) {
            // 播放相应的视频
            mVideoView.setMediaController(new MediaController(this));
            mVideoView.setVideoURI(Uri.parse(path));
            mVideoView.start();
        }
    }
}
